package com.kimari.dao.role;

import com.kimari.dao.BaseDao;
import com.kimari.pojo.Role;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author Kimariyb
 * @Date 2022/01/30/19:57
 * @Description
 */
public class RoleDaoImpl implements RoleDao{
    @Override
    public List<Role> getRoleList(Connection connection) throws Exception {
        PreparedStatement pstm = null;
        ResultSet rs = null;
        List<Role> roleList = new ArrayList<Role>();

        if (connection != null) {
            String sql = "SELECT * FROM `smbms_role`";
            Object[] params = {};
            rs = BaseDao.execute(connection, pstm, rs, sql, params);

            while (rs.next()) {
                Role role = new Role();
                role.setId(rs.getInt("id"));
                role.setRoleCode(rs.getString("roleCode"));
                role.setRoleName(rs.getString("roleName"));
                roleList.add(role);
            }
        }
        BaseDao.closeResource(null, pstm, rs);
        return roleList;
    }
}
